package com.longcai.piaojia.conn;

import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/1/10.
 */
@HttpInlet(Conn.ACTIVITY_INDEX)
public class LatestListGet extends BaseAsyGet<LatestListGet.LatestEntity> {

    public int page;

    public LatestListGet(AsyCallBack<LatestEntity> asyCallBack) {
        super(asyCallBack);
    }

    @Override
    protected LatestEntity parser(JSONObject object) throws Exception {

        TOAST = object.optString("message");

        if (object.optInt("code") == 200) {

            JSONObject mainObject = object.optJSONObject("data");

            LatestEntity latestEntity = new LatestEntity();

            latestEntity.current_page = mainObject.optInt("current_page");
            latestEntity.per_page = mainObject.optInt("per_page");
            latestEntity.total = mainObject.optInt("total");
            latestEntity.program_phone = object.optString("program_phone");

            JSONArray array = mainObject.optJSONArray("data");

            for (int i = 0; i < array.length(); i++) {

                JSONObject entityObject = array.optJSONObject(i);

                Latest latest = new Latest();

                latest.id = entityObject.optString("id");
                latest.picurl = Conn.IMAGE_BANNER_URL + entityObject.optString("picurl");
                latest.title = entityObject.optString("title");


                latest.type = entityObject.optString("type");

                latest.weburl = entityObject.optString("weburl");

                latestEntity.latestList.add(latest);

            }

            return latestEntity;

        }


        return null;
    }

    public static class  LatestEntity {

        public int total, per_page, current_page;

        public String program_phone;

        public List<Latest> latestList = new ArrayList<>();

    }

    public static class Latest {

        public String id, picurl, title,type,weburl;

    }
}
